entrycompletion: Export gtk_entry_completion_compute_prefix()
authorBenjamin Otte <otte@redhat.com>
Sat, 5 Nov 2011 19:38:28 +0000 (20:38 +0100)
committerBenjamin Otte <otte@redhat.com>
Fri, 16 Dec 2011 19:09:12 +0000 (20:09 +0100)
I want to use it in the file chooser entry autocomplete code.

docs/reference/gtk/gtk3-sections.txt
gtk/gtk.symbols
gtk/gtkentrycompletion.c
gtk/gtkentrycompletion.h

index 57d49335d3acf9a6f25db72bd16e60e5b8b4d548..73f8a7c1ad351bd69cab132d756782885009c7f0 100644 (file)
@@ -1135,6 +1135,7 @@ gtk_entry_completion_get_model
 gtk_entry_completion_set_match_func
 gtk_entry_completion_set_minimum_key_length
 gtk_entry_completion_get_minimum_key_length
+gtk_entry_completion_compute_prefix
 gtk_entry_completion_complete
 gtk_entry_completion_get_completion_prefix
 gtk_entry_completion_insert_prefix
index 40631c3331523783052b8dcc1fcea68ac9f84c7d..9123393f61ab835d8bd29a0f2b17d407fbeb1776 100644 (file)
@@ -820,6 +820,7 @@ gtk_entry_buffer_new
 gtk_entry_buffer_set_max_length
 gtk_entry_buffer_set_text
 gtk_entry_completion_complete
+gtk_entry_completion_compute_prefix
 gtk_entry_completion_delete_action
 gtk_entry_completion_get_completion_prefix
 gtk_entry_completion_get_entry
index 4847b9d696a47b9f5ca5ddd8d02ef7068cdd5fd1..b7e9b6b3e48adefb07c39aab2cb85e9f47e562bd 100644 (file)
@@ -1693,19 +1693,32 @@ gtk_entry_completion_cursor_on_match (GtkEntryCompletion *completion,
   return TRUE;
 }
 
-static gchar *
-gtk_entry_completion_compute_prefix (GtkEntryCompletion *completion)
+/**
+ * gtk_entry_completion_compute_prefix:
+ * @completion: the entry completion
+ * @key: The text to complete for
+ *
+ * Computes the common prefix that is shared by all rows in @completion
+ * that start with @key. If no row matches @key, %NULL will be returned.
+ * Note that a text column must have been set for this function to work,
+ * see gtk_entry_completion_set_text_column() for details. 
+ *
+ * Returns: (transfer: full): The common prefix all rows starting with @key
+ *   or %NULL if no row matches @key.
+ *
+ * Since: 3.4
+ **/
+gchar *
+gtk_entry_completion_compute_prefix (GtkEntryCompletion *completion,
+                                     const char         *key)
 {
   GtkTreeIter iter;
   gchar *prefix = NULL;
   gboolean valid;
-  const gchar *key;
 
   if (completion->priv->text_column < 0)
     return NULL;
 
-  key = gtk_entry_get_text (GTK_ENTRY (completion->priv->entry));
-
   valid = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (completion->priv->filter_model),
                                          &iter);
 
@@ -1874,7 +1887,9 @@ gtk_entry_completion_insert_prefix (GtkEntryCompletion *completion)
     g_signal_handler_block (completion->priv->entry,
                             completion->priv->insert_text_id);
 
-  prefix = gtk_entry_completion_compute_prefix (completion);
+  prefix = gtk_entry_completion_compute_prefix (completion,
+                                                gtk_entry_get_text (GTK_ENTRY (completion->priv->entry)));
+
   if (prefix)
     {
       g_signal_emit (completion, entry_completion_signals[INSERT_PREFIX],
index 368b94434280293d90065a2421385707a3b3814a..0b19e6dcafc8abf86b9c5110ddbeb29f08829b61 100644 (file)
@@ -114,6 +114,8 @@ void                gtk_entry_completion_set_match_func         (GtkEntryComplet
 void                gtk_entry_completion_set_minimum_key_length (GtkEntryCompletion          *completion,
                                                                  gint                         length);
 gint                gtk_entry_completion_get_minimum_key_length (GtkEntryCompletion          *completion);
+gchar *             gtk_entry_completion_compute_prefix         (GtkEntryCompletion          *completion,
+                                                                 const char                  *key);
 void                gtk_entry_completion_complete               (GtkEntryCompletion          *completion);
 void                gtk_entry_completion_insert_prefix          (GtkEntryCompletion          *completion);